import { BaseHttpClient } from "@/utils/request";

const http = new BaseHttpClient("/");

const handleMenuList = (parent: string, arr: Menu.MenuOptions[]) =>
  arr.map(item => {
    item.parent = parent;
    if (item.children) handleMenuList(item.path, item.children);
    return item;
  });
export const pageList = async (): Promise<HttpResType<listResponse<Menu.MenuOptions>>> => {
    const { data } = await http.get<HttpResType<Menu.MenuOptions[]>>("authMenuList");
    return {
      code: 200,
      data: {
        total: data.length,
        size: 10,
        current: 1,
        pages: 1,
        data: handleMenuList("parent", data)
      },
      msg: "success"
    };
  },
  handleMenu = (json: Object, fileName: string, handleType: string) =>
    http.post(`menu/${handleType}`, {
      fileName,
      json
    });
